package com.mjp.learn.multi.basic;

/**
 * yield 方法 使得当前线程暂时让出资源统一进入竞争
 */
public class Demo07 implements Runnable{

    private String name;

    public Demo07(String name){
        this.name = name;
    }

    @Override
    public void run() {
        System.out.println(this.name+" start!");
        for(int i = 0 ; i < 100 ; i ++){
            if("t1".equals(name) && i==5){
                System.out.println(name+":"+i+"--------yield-------");
                Thread.yield();
            }
        }
        System.out.println(this.name+" end!");
    }

    public static void main(String[] args) {
        Thread t1 = new Thread(new Demo07("t1"));
        Thread t2 = new Thread(new Demo07("t2"));
        t1.start();
        t2.start();
    }
}
